package com.example.shop_front_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.shop_front_api.entity.News;
import com.example.shop_front_api.mapper.NewsMapper;
import com.example.shop_front_api.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public int addNews(News news) {
        return newsMapper.insert(news);
    }

    @Override
    public News getNewsById(Long id) {
        return newsMapper.selectById(id);
    }

    @Override
    public List<News> getAllNews() {
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        return newsMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteNewsById(Long id) {
        return newsMapper.deleteById(id);
    }
}